package br.com.scitv.tela;

import java.awt.event.KeyEvent;
import java.net.URL;

import javax.media.Manager;
import javax.media.Player;

import br.com.scitv.SCITV;
import br.com.scitv.action.SCITVAction;

import com.sun.dtv.lwuit.Form;
import com.sun.dtv.lwuit.Image;
import com.sun.dtv.lwuit.Label;
import com.sun.dtv.lwuit.geom.Dimension;
import com.sun.dtv.ui.event.RemoteControlEvent;
import com.sun.dtv.ui.event.UserInputEvent;

public class TelaInicial extends Tela{

	private Label carrinho;
	private SCITVAction action;
	private Form form;
	
	
	public TelaInicial(SCITVAction action){
		this.action = action;
		form = new Form();
	}
	

	public void userInputEventReceived(UserInputEvent inputEvent) {			
		com.sun.dtv.ui.event.KeyEvent event = (com.sun.dtv.ui.event.KeyEvent) inputEvent;

		if(event.getID() == KeyEvent.KEY_RELEASED){
			return;
		}

		switch(event.getKeyCode()){
		case RemoteControlEvent.VK_COLORED_KEY_0: 
			action.apresentaProduto();
			break;
		}

	}

	public void addComponentes(){
		int borda = 50;
		dtvcontainer.addComponent(form);
		
		carrinho = new Label();
		Image image = null;
		try {
			String path =  SCITV.getPropiedadePathImagem("img.carrinho");
			image = Image.createImage( path );
			carrinho.setIcon(image);
		} catch (Exception e) {		
			System.out.println("Error while loading image " +  e.getMessage());
		}

		carrinho.setX( borda );
		carrinho.setY( 400 );
		carrinho.setSize( new Dimension( image.getWidth(), image.getHeight()  ));
		
		form.addComponent(carrinho);

		
		form.repaint();
	}

}
